package nicg.st.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import nicg.st.entity.EvalDataEnterVO;
import nicg.st.entity.battle.ZZNLVO;
import nicg.st.service.UserService;
import nicg.st.service.evaldataenterservice.EvalDataEnterService;
import nicg.st.util.ErrorCode;
import nicg.st.util.ResponseUtil;

/**
 * @author
 * @Description
 * @date 2019/11/3 22:28
 */
@RestController
@RequestMapping("/api/evaldataenter")
public class EvalDataEnterController {

	@Autowired
	EvalDataEnterService evalDataEnterService;

	@Autowired
	UserService userService;

	// 获取当前的任务信息列表
	@RequestMapping(value = "/getTasks", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getTasks() {
//			communicate.startService();
		return evalDataEnterService.getTasks();
	}

	// 获取作战能力
	@RequestMapping(value = "/getZZNL", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getZZNL(String BDMC) {
		if (evalDataEnterService.getZZNL(BDMC) == null) {
			ZZNLVO zznl = new ZZNLVO();
			zznl.setBznl(1);
			zznl.setDjnl(2);
			zznl.setFhnl(3);
			zznl.setJdnl(4);
			zznl.setXxnl(5);
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取作战能力失败", zznl);
		} else {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取作战能力成功", evalDataEnterService.getZZNL(BDMC));
		}
	}

	// 根据用户信息获取当前的任务信息和指标体系信息
	@RequestMapping(value = "/getInfos", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getInfos(String userId) {
		return evalDataEnterService.getInfos(userId);
	}

	/**
	 * @return java.util.List<evaldataenter.dao.entity.VO.IndicatorTree>
	 * @Description 获取需要录入的指标体系部分
	 * @Date 2019/7/20 15:40
	 * @Param [indicatorId]
	 **/
	@RequestMapping(value = "/buildIndicatorTree", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String buildIndicatorTree(int userId, int indicatorId) { // List<IndicatorTree>
		return evalDataEnterService.buildIndicatorTree(userId, indicatorId);
	}

	/**
	 * @return java.lang.String
	 * @Description 评估
	 * @Date 2019/6/12 22:23
	 * @Param [tempOpId]
	 **/
	@RequestMapping(value = "/eval", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String eval(@RequestBody EvalDataEnterVO evalDataEnterVO) {
		return evalDataEnterService.eval2(evalDataEnterVO);
	}

	/**
	 * @return java.lang.String
	 * @Description 及时评估接口
	 * @Date 2019/6/12 22:23
	 * @Param [userId, rwnm]
	 */
//    @RequestMapping(value = "/justEval", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String eval(int userId, String rwnm) {
//        return evalDataEnterService.justEval(userId, rwnm);
//    }

	/**
	 * @return java.lang.String
	 * @Description 子任务
	 * @Date 2019/6/12 22:23
	 * @Param [tempOpId]
	 **/
	@RequestMapping(value = "/getScheme", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getScheme(String schemeName) {
		System.out.println(schemeName);
		return evalDataEnterService.getScheme(schemeName);
	}

	@RequestMapping(value = "/getScheme2", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getScheme2(String rwnm) {
		System.out.println(rwnm);
		return evalDataEnterService.getScheme2(rwnm);
	}

	@RequestMapping(value = "/getCurUserId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getCurUserId() {
		if (userService.getCurUserId() == null) {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户失败", userService.getCurUserId());
		} else {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户成功", userService.getCurUserId());
		}
	}
}